package com.jiayu.wheel.exception;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

/**
 * 自定义全局捕捉异常
 * 对exception或自定义的异常进行特殊处理,不让乱七八糟的异常信息直接怼给客户
 * @author Administrator
 */
@ControllerAdvice
public class CustomerBusinessExceptionHandler {

    @ResponseBody
    @ExceptionHandler(BusinessException.class)
    public Map<String,Object> businessExceptionHandler(BusinessException be){
        Map<String,Object> map = new HashMap<>(2);
        map.put("code",be.getCode());
        map.put("msg",be.getMessage());
        return map;
    }


//    @ResponseBody
//    @ExceptionHandler(Exception.class)
//    public Map<String,Object> exceptionHandler(Exception be){
//        Map<String,Object> map = new HashMap<>();
//        map.put("code",999999);
//        map.put("msg","哎呀，服务端出问题啦！");
//        return map;
//    }

}
